home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2216 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: eql.caltech.edu!rankin
  2. From: rankin@eql.caltech.edu (Pat Rankin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem calling LIB$FIND_FILE on VAX
  5. Date: 19 Jan 1996 14:02 PST
  6. Organization: California Institute of Technology
  7. Distribution: world
  8. Message-ID: <19JAN199614022139@eql.caltech.edu>
  9. References: <1996Jan18.135459.1@vax.sbu.ac.uk>
  10. NNTP-Posting-Host: bear.eql.caltech.edu
  11. News-Software: VAX/VMS VNEWS 1.41x8  
  12.  
  13. In article <1996Jan18.135459.1@vax.sbu.ac.uk>, tonyh@vax.sbu.ac.uk writes...
  14. > I'm having difficulty trying to call the lib$find_file(,,,,,,) VAX
  15. > Run-Time-Library (RTL) command from within a C program. I think my
  16. > problem is not with the parameters of the actual lib$ call itself,
  17. > but with the "$descriptor" part that actually holds the values, I've
  18. > been through the VAX manuals and the "descriptor" part is still unclear
  19. > to me. Am I accessing it correctly?...
  20.  
  21.      This topic would be more appropriate in comp.os.vms.
  22.  
  23. >%SYSTEM-F-ACCVIO, access violation, reason mask=01, virtual address=010E0102,
  24. [...]
  25.  
  26.      That virtual "address" looks like the value of the first 32 bits of
  27. one of your string descriptors.
  28.  
  29. [...]
  30. >   struct dsc$descriptor_s FileFound;
  31. [...]
  32. >    /* Call library function  Lib$find_file(,,,,) */
  33. >   status = lib$find_file( descriptor( FName ), FileFound,
  34. >                                ContexVar, 0, 0, 0, 1 );
  35.  
  36.      You are passing `FileFound' by value but lib$find_file expects to
  37. receive it by reference.  You need to use `&FileFound' to pass a pointer
  38. to your variable.  `ContexVar' and those integer constants also have
  39. the same problem.  (Actually worse; you're using unadorned 0 where you
  40. ought to be using null pointers, and clearly there's no prototype in
  41. scope or the `FileFound' mismatch would have been caught by the compiler.)
  42. lib$XXX routines take arguments by reference so that they're relatively
  43. straightforward to use with any programming language; C code needs to
  44. construct pointers rather than pass immediate values.
  45.  
  46. >   if (status == SS$_NORMAL) {
  47. >      FileFound.dsc$a_pointer[ FileFound.dsc$w_length ] = '\0';
  48. >   }
  49.  
  50.      You should not be checking for an explicit value; check for an odd
  51. number, which is the most generic way to test VMS condition codes for
  52. success.  And since `FileFound' defines a static string, lib$find_file
  53. will not touch its length field, so your '\0' would always end up being
  54. stored at `instr[255]' and not actually trim the resulting file name.
  55. All lib$XXX routines which write to static strings will pad their output
  56. values with trailing spaces to fill out the full length defined for the
  57. string.  Since VMS file names never have trailing spaces in them, you
  58. can trim the string by starting at the end of the buffer and backing up
  59. until you hit any non-space character or the beginning of the buffer.
  60. Or you could switch to dynamic strings, but I'd advise against that.
  61. With dynamic allocation you would have the exact length, but there'd be
  62. no guarantee of room in the allocated buffer to append a trailing NUL
  63. byte for use as a normal C-style string.
  64.  
  65.         Pat Rankin, rankin@eql.caltech.edu
  66.